package com.show.service.unit;


import com.show.dto.Tree;
import com.show.util.QueryUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 部件类型Service
 *
 * @author liukai
 */
@Service
public class UnitTypeService {

    private QueryUtil queryUtil;

    @Autowired
    public UnitTypeService(QueryUtil queryUtil) {
        this.queryUtil = queryUtil;
    }


    /**
     * 查询部件类型树 用于ztree
     *
     * @author liukai
     */
    public List<Tree> getUnitTypeTree() {
        String sql = "SELECT\n" +
                "  unit_type.unit_type_id                                                                                                   AS id,\n" +
                "  (CASE WHEN unit_type.parent_unit_type_id IS NULL THEN '0' ELSE unit_type.parent_unit_type_id END)                        AS pId,\n" +
                "  unit_type.unit_type_name                                                                                                 AS name,\n" +
                "  (CASE WHEN unit_type.parent_unit_type_id IS NULL THEN 'false' END)                                                       AS open\n" +
                "FROM\n" +
                "  unit_type AS unit_type\n" +
                "WHERE\n" +
                "  unit_type.sts = '0'";
        return queryUtil.query(sql, Tree.class);
    }

}
